//package com.wave.traffic.NetSDKDemo;
//
//import cn.hutool.core.util.NumberUtil;
//import com.wave.traffic.alarm.Alarm;
//import com.wave.traffic.alarm.AlarmResult;
//import com.wave.traffic.alarm.Param;
//import com.google.gson.Gson;
//import com.google.gson.GsonBuilder;
//import com.sun.jna.Pointer;
//import com.wave.traffic.util.SocketClientUtil;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.nio.charset.StandardCharsets;
//import java.util.Date;
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//import java.util.concurrent.TimeUnit;
//
//public class FRadarCallback implements HCNetSDK.FRemoteConfigCallBack {
//
//    private final static Logger logger = LoggerFactory.getLogger(FRadarCallback.class);
//
//    private static final String HUMAN = "human";
//
//    private static final String VEHICLE = "vehicle";
//
//    private static boolean bool = false;
//
//    private static Map<String,Object> resultMap = new ConcurrentHashMap<>();
//
//    private final static ExecutorService executorService = Executors.newFixedThreadPool(3);
//
//    @Override
//    public void invoke(int dwType, Pointer lpBuffer, int dwBufLen, Pointer pUserData) {
//        // System.out.println("长连接回调获取数据,NET_SDK_CALLBACK_TYPE_STATUS:" + dwType);
//        switch (dwType) {
//            case 0: //NET_SDK_CALLBACK_TYPE_STATUS
//                HCNetSDK.BYTE_ARRAY struCallbackStatus = new HCNetSDK.BYTE_ARRAY(4);
//                struCallbackStatus.write();
//                Pointer pStatus = struCallbackStatus.getPointer();
//                pStatus.write(0, lpBuffer.getByteArray(0, struCallbackStatus.size()), 0, 4);
//                struCallbackStatus.read();
//
//                int iStatus = 0;
//
//                for (int i = 0; i < 4; i++) {
//                    int ioffset = i * 8;
//                    int iByte = struCallbackStatus.byValue[i] & 0xff;
//                    iStatus = iStatus + (iByte << ioffset);
//                }
//
//                switch (iStatus) {
//                    case 1000: //NET_SDK_CALLBACK_STATUS_SUCCESS
//                        System.out.println("获取成功并且结束, dwStatus:" + iStatus);
//                        System.out.println("error code："+ Alarm.hCNetSDK.NET_DVR_GetLastError());
//                        break;
//                    case 1001:
//                        System.out.println("正在获取中..., dwStatus:" + iStatus);
//                        System.out.println("error code："+ Alarm.hCNetSDK.NET_DVR_GetLastError());
//                        break;
//                    case 1002:
//                        System.out.println("获取失败, dwStatus:" + iStatus);
//                        System.out.println("error code："+ Alarm.hCNetSDK.NET_DVR_GetLastError());
//                        break;
//                }
//                break;
//            case 2: //获取状态数据
//                HCNetSDK.NET_DVR_ALARM_SEARCH_RESULT alarmSearchResult = new HCNetSDK.NET_DVR_ALARM_SEARCH_RESULT();
//                alarmSearchResult.write();
//                Pointer searchResultPointer = alarmSearchResult.getPointer();
//                searchResultPointer.write(0, lpBuffer.getByteArray(0, alarmSearchResult.size()), 0, alarmSearchResult.size());
//                alarmSearchResult.read();
//
////                HCNetSDK.BYTE_ARRAY userData = new HCNetSDK.BYTE_ARRAY(32);
////                userData.write();
////                userData.getPointer().write(0, pUserData.getByteArray(0, userData.size()), 0, userData.size());
////                userData.read();
//
//                // System.out.println("--------------------user " + new String(userData.byValue,StandardCharsets.UTF_8).substring(7,8));
//
//
//                String sSerialNumber = new String(alarmSearchResult.struAlarmer.sSerialNumber, StandardCharsets.UTF_8);
//                //雷视-枪球SN号码长度不同
//                String deviceId = sSerialNumber.substring(4, 11) + sSerialNumber.substring(25, 34);
//                if ((alarmSearchResult.dwAlarmLen > 0) && (alarmSearchResult.pAlarmInfo != null)) {
//                    executorService.submit(new Runnable() {
//                        @Override
//                        public void run() {
//
//                            String body = new String(alarmSearchResult.pAlarmInfo.getByteArray(0, alarmSearchResult.dwAlarmLen));
//                            //System.out.println("fffffffff result: " + body);
//                            Gson gson = new GsonBuilder().serializeNulls().create();
//                            body = body.substring(body.indexOf("{"), body.lastIndexOf("}") + 1);
//                            //System.out.println("uuuuuuuu result: " + body);
//                            AlarmResult alarmResult = gson.fromJson(body, AlarmResult.class);
//                            //System.out.println(body.length());
//                            //if (body.length() > 281) {
//                            if (alarmResult.getDatas() != null && !alarmResult.getDatas().isEmpty()) {
//                                //if(StringUtils.isNotEmpty(alarmResult.getIpAddress()) && StringUtils.isNotEmpty(alarmResult.getDateTime().toString())) {
//                                for (Param param : alarmResult.getDatas()) {
//                                    if (VEHICLE.equals(param.getTargetType())) {
//                                        bool = true;
//                                    }
//                                }
//                                //}
//                            }
//                            else { //无人且无车
//                                bool = false;
//                            }
//                            //}
//
//                        }
//                    });
//
//
//                }
//                break;
//            default:
//                break;
//        }
//    }
//
//    public static boolean isVehicle(){
//        return bool;
//    }
//
//}
